namespace CSharpPro._1103;


public class User
    {
        private string _username;   
        private string _password;   
        private string _email;    
        
        public string Username
        {
            get => _username;
            private set 
            {
                if (string.IsNullOrWhiteSpace(value))
                    throw new ArgumentException("用户名不能为空或空格！");
                _username = value;
            }
        }

        public string Password
        {
            get => _password;
            private set
            {
                if (value.Length < 6)
                    throw new ArgumentException("密码长度不能少于6位！");
                _password = value;
            }
        }

        public string Email
        {
            get => _email;
            set
            {
                if (!value.Contains("@") || !value.Contains("."))
                    throw new ArgumentException("邮箱格式不正确！");
                _email = value;
            }
        }
        
        public User(string username, string password, string email = "")
        {
            Username = username;  
            Password = password;   
            if (!string.IsNullOrWhiteSpace(email))
                Email = email;    
        }
    }

